Skip to content

Conversation

rachelks
Copy link
Member

Summary

Closes #20.

  • Adds SortSelect: an accessible sort selector with Title A-Z, Title Z-A, Newest first, and Oldest first
  • Sorts the already-fetched books client-side without additional API requests
  • Persists the selected sort option in sessionStorage under t19.preferences together with the selected subject
  • Restores the selected sort option on reload and safely falls back to the default for missing/corrupt data
  • Integrates the sorted book list with navigation and the book jump list

User flow

  1. Select a sorting option from "Sort by".
  2. The displayed books are reordered without a new API request.
  3. Navigate through the books or select one from the book list in the new order.
  4. Refresh the page: the selected sorting option remains for the current session.

Tests

  • sortBooks tests verify all four sorting options and that the original books array is not mutated
  • SortSelect tests verify the accessible select, available options, and sort changes
  • App tests verify that changing sort causes no additional API requests
  • App tests verify that the selected sort is restored from sessionStorage
  • Snapshots updated deliberately for the new sort control
  • npm test, npm run lint, npm run build, and npm run format:check pass

Validation

  • npm run format:check
  • npm run lint
  • npm test — 42 passed
  • npm run build

@rachelks rachelks requested a review from a team as a code owner September 10, 2026 10:45
@rachelks rachelks changed the title Feat/20 sorting feat: Sorting of books with sessionStorage persistence Sep 10, 2026
@erikhfj
Copy link
Member

erikhfj commented Sep 10, 2026

Code review pass (automated, thorough): no bugs found. All 51 tests + format/lint/build verified on feat/20-sorting @ 08b3aa7.

Verified in depth: sortBooks is a stable, non-mutating sort with an index tiebreaker; null publish years consistently sink to the end regardless of direction; title sorts negate localeCompare; persistence merges into existing t19.preferences and preserves unrelated keys; isSortOption guard covered by tests on both layers; the snapshot's cover→placeholder switch is expected (title-asc puts the coverless fixture first).

Non-blocking notes:

  1. UX consistency (low): changing sort keeps the position rather than the book — while subject change (in feat: wire subject filter into the viewer with index reset #27) resets the index. Consider making both preferences consistent (reset on sort change too) during the feat: Wire preferences together and verify reload persistence #22 integration.
  2. Deliberate? FavoritesView receives the unsorted books while navigation/jump list use sortedBooks — favorites always shows API order. Fine if intentional (PR description scopes sorting to navigation), just confirm it's conscious.
  3. Maintainability: isSortOption duplicates the SortOption union — deriving it from SORT_OPTIONS (exported from utils/sortBooks) would give one source of truth when options change.
  4. DEFAULT_SORT is exported but only used internally in usePreferences.ts — harmless.

Ready to merge from my perspective.

@erikhfj erikhfj merged commit 8c9fc72 into main Sep 10, 2026
1 check passed
@erikhfj erikhfj deleted the feat/20-sorting branch September 10, 2026 20:02
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Sorting of books with sessionStorage persistence
2 participants